package java07;

import java.util.Scanner;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main048 {
    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()){
            int n = sc.nextInt();//任务数
            int poolSize = sc.nextInt();//最多使用的线程数
            /*你的答案：这里建立用于等待的CountDownLatch对象,变量名为latch*/
            /*你的答案：这里是创建符合条件的执行器的代码*/
            /*你的答案：这里是执行n个任务的循环代码*/
            CountDownLatch latch = new CountDownLatch(n);
            MyTask task = new MyTask(latch);
            ExecutorService exec = Executors.newFixedThreadPool(poolSize);
            for(int i = 0;i < n;i++){
            exec.execute(task);
            }

            exec.shutdown();
            latch.await();//主线程阻塞，直到前面线程都执行完，再执行后面的代码
            /*这里是系统的其他代码*/
        }
        sc.close();
    }
}

class MyTask implements Runnable{
	CountDownLatch latch;

	public MyTask(CountDownLatch latch) {
		// TODO Auto-generated constructor stub
		this.latch=latch;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}
	
}